package com.xykj.enterprise.wechat.ext.api.contacts.member;

import com.xykj.enterprise.wechat.bean.ext.BaseResp;
import com.xykj.enterprise.wechat.ext.service.contacts.ContactsUserService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Function(description = "二次验证", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "应用场景标识", required = true),

        @Parameter(name = "userid", type = Type.String, description = "账号", required = true),

})
@Component
public class AuthSucc implements Action {

    @Autowired
    private ContactsUserService contactsUserService;

    @Override
    public Response execute(Request request) throws Exception {
        String userid = request.getString("userid");
        BaseResp rsp = contactsUserService.authSucc(
                request.getString("access_token"), userid
        );
        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success();
    }
}
